import shutil
import os
import chardet

def get_file_list(file_path=None):
    """获取文件夹列表"""
    if not file_path:
        return None
    # file_set = set()
    file_list = []
    try:
        for fpath, dirs, fs in os.walk(file_path):
            # file_set = file_set | set(fs)
            # print(fs)
            for t in fs:
                file_list.append(os.path.join(fpath, t))
    except:
        pass
        print("err")
        # return (file_set)
    return (file_list)


if __name__ == "__main__":
    folder = r"E:\足力健环境对比\数据库\20211231_16点对比"
    now_number = 0
    for file in get_file_list(folder):
        now_number += 1
        print(now_number)
        with open(file, mode='rb') as ft:
            data = ft.read()
            char_f = (chardet.detect(data)['encoding'])

        with open(file, encoding=char_f) as fp_in:
            a = fp_in.readlines()
            b = ''.join(a[1:])
            with open("tmp.sql", 'w', encoding='utf-8') as fp_out:
                fp_out.writelines(b)
        os.remove(file)
        shutil.move("tmp.sql", file)
